import { songListDetail } from './../../api/model/songList.d'
import { defineStore } from 'pinia'
import { reqPlayList } from '@/api/recommend'
import { songOfList, Songs } from '@/api/model/song'
import { useSongStore } from '../song'

let songStore: any
setTimeout(() => {
  songStore = useSongStore()
}, 0)
export const useSongListStore = defineStore({
  id: 'SongList',
  state: (): { playList: Songs; index: number } => ({
    //当前歌单信息
    playList: [],
    index: 0,
  }),

  actions: {
    async getPlayList(songListID: number, limit?: number) {
      let { songs } = await reqPlayList(songListID, limit)
      console.log(songs)
      this.playList = songs
      this.index = 0
      //  playList.value = songs
    },
    setIndex(ind: number) {
      this.index = ind
    },
    addSong(song: songOfList) {
      this.playList.push(song)
    },
    next() {
      if (this.index >= this.playList.length) {
        console.log('已经是最后一首')

        return
      }
      songStore.setId(this.playList[++this.index].id)
    },
    pre() {
      if (this.index <= 0) {
        console.log('已经是第一首')
        return
      }
      songStore.setId(this.playList[--this.index].id)
    },
  },
})
